package collection.stream;

import org.omg.PortableInterceptor.INACTIVE;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StreamApiDemo2 {
    public static void main(String[] args) {
        Random rand = new Random();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++){
            list.add(rand.nextInt(100));

        }
        System.out.println(list);

        Optional<Integer> value = list.stream().min((e1,e2)->e1-e2);
        System.out.println("最小值是:"+value.get());

        value = list.stream().max((e1,e2)->e1-e2);
        System.out.println("最大值是:"+value.get());

        boolean anyMatch = list.stream().anyMatch(x -> x % 2 == 0);
        System.out.println("集合中是否有偶数:"+anyMatch);

        boolean allMatch = list.stream().allMatch(x -> x % 2 == 0);
        System.out.println("集合中是否全是偶数:"+allMatch);

        boolean noneMatch = list.stream().noneMatch(x -> x % 2 == 0);
        System.out.println("集合中是否没有偶数:"+noneMatch);

        int sum = list.stream().reduce(0,(x,y)->x+y);
        System.out.println("集合中所有元素的和:"+sum);
    }
}
